# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/defconfig
# Maintainer: Jianhua Lu <lujianhua000@gmail.com>

_flavor="postmarketos-qcom-sm8250"
pkgname=linux-$_flavor
pkgver=6.12.0
pkgrel=1
pkgdesc="Mainline kernel fork for SM8250"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/sm8250-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-nftables
	pmb:kconfigcheck-community
"
makedepends="
	bash
	bison
	findutils
	flex
	openssl-dev
	perl
	postmarketos-installkernel
	python3
"

# Source
_tag="sm8250-$pkgver"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_tag.tar.gz::https://gitlab.com/sm8250-mainline/linux/-/archive/$_tag/linux-$_tag.tar.gz
	$_config
"
builddir="$srcdir/linux-$_tag"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$arch" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	mkdir -p "$pkgdir"/boot

	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir/boot/dtbs"
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
6de31ce37ce6870c2ee12a72fdd4b4efc52b2dc1b031ffc0d2d049e882bbc9cb1e86507ddee37cb4d910e43ade217c017dfdd57b2e95363c2ccf6f7f29a68fb1  linux-postmarketos-qcom-sm8250-sm8250-6.12.0.tar.gz
78745823967530af2132cdadb770c0f97b147b71f8332de174a759f21bd8a7416202d0466cc23fb54f0aa11df44a35e4e17f96f41d688153cd245843d1f69479  config-postmarketos-qcom-sm8250.aarch64
"
